import { createSlice } from '@reduxjs/toolkit'

const counterSlice = createSlice({
  name: "counter",
  initialState: {
    counter: 888
  },
  reducers: {
    addNumber(state, action) {
      //redux-toolkit内部使用了immer-js，修改字段时，会返回一个新对象
      state.counter = state.counter + action.payload
    },
    subNumber(state, action) {
      state.counter = state.counter - action.payload
    },
  }

})

export const { addNumber, subNumber } = counterSlice.actions

export default counterSlice.reducer